# _*_ encoding:utf-8 _*_
from django_redis import get_redis_connection


def handel_list(serializer, user):

    conn = get_redis_connection('collect_thumbup')

    def func(_dict):
        hasthumbup_list = [int(i) for i in conn.smembers(f'hasthumbup_{user.id}')]
        hcollected_list = [int(i) for i in conn.smembers(f'collected_{user.id}')]
        _dict['hasthumbup'] = _dict['id'] in hasthumbup_list
        _dict['collected'] = _dict['id'] in hcollected_list
        return _dict

    if isinstance(serializer.data, dict):
        return func(serializer.data)
    else:
        for spit in serializer.data:
            func(spit)





